//
//  DetailsViewController.m
//  SelfDriving
//
//  Created by apple on 16/1/29.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "DetailsViewController.h"
#import "BusinessService+FJ.h"
#import "BusinessService+WD.h"
#import "zanCell.h"
#import "KYExpressionInputView.h"
#import "FriendDetailsMainVC.h"
#import "EmojiTextAttachment.h"
#import "UIButton+IndexPath.h"
#import "ReportViewController.h"
#import "EmotionInputView.h"
//动态详细
@interface DetailsViewController ()<UITableViewDataSource,UITableViewDelegate,BaseTableDetelage,UICollectionViewDelegate,UICollectionViewDataSource,UITextViewDelegate,KYExpressionInputViewDelegate,UIActionSheetDelegate,MLEmojiLabelDelegate,UIActionSheetDelegate,EmotionInputViewDelegate>
@property (weak, nonatomic) IBOutlet BaseTable *table;
@property (strong, nonatomic) UITextView *hfText; //回复输入框
@property (strong, nonatomic) UIView *inputView;
@property (weak, nonatomic) IBOutlet UIView *searView;  //xhw:高度为60 y值为ScreenHeight-60;
@property (strong, nonatomic) UIButton *bqBtn;  //表情按钮
@property (strong, nonatomic) UIButton *senderBtn;
@property (nonatomic, strong) EmotionInputView *emojiView;
@property (nonatomic,assign)BOOL isShowEmojiView;

@property (nonatomic,strong)UIView *viewBottom;
@property (nonatomic, assign)BOOL shouldChangeBottom;
@property (nonatomic, strong)UITapGestureRecognizer *tapGestureRecognizer;
@property (nonatomic,assign)CGRect endKeyboardRect;
@property (nonatomic,assign)int type;
@property (nonatomic, assign)BOOL isHidenViewBottom;

@end

@implementation DetailsViewController
{
    NSMutableArray *data;
    UILabel *notlabel;
    int cont;
    KYExpressionInputView *XHWEmojiView; //表情view
    
    BOOL isUp;
    int isReplySingle;//是否回复单人
    NSMutableDictionary *ReplySingle;//回复单人集合
    DTModel *huifumsg;
    MPMoviePlayerController *moviePlayer;
    
    NSString *bq;
    UIView *zanview;
}

- (void)rightBarItemClick {

    UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"MS"
                                                                 bundle:[NSBundle mainBundle]];
    ReportViewController *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"ReportViewController"];
    searchResultDetailController.uid = _model.uid;
    searchResultDetailController.type = @"5";
    searchResultDetailController.content = _model.id;
    [self.navigationController pushViewController:searchResultDetailController animated:YES];
}

//xhw2018-2-23加
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    [self tapRespond:nil];
}


- (void)viewDidLoad {
    
    _viewBottom = [[UIView alloc] init];
    _viewBottom.frame = CGRectMake(0,_table.frame.origin.y + _table.frame.size.height, SCRE_WIDTH, 49);
    _viewBottom.backgroundColor = [UIColor grayColor];
    [self.view addSubview:_viewBottom];
    _shouldChangeBottom = YES;
    _endKeyboardRect = CGRectZero;
    
    _emojiView = [[EmotionInputView alloc] initWithDelegate:self];
    _emojiView.backgroundColor = [UIColor whiteColor];
    _emojiView.frame = CGRectMake(0, _viewBottom.frame.origin.y + _viewBottom.frame.size.height, SCRE_WIDTH, 192);
    [self.view addSubview:_emojiView];
    self.edgesForExtendedLayout = UIRectEdgeNone;//xhw2018-2-7加
    
    
    self.navigationController.navigationBarHidden = NO;
    [super viewDidLoad];
    
    //xhw2018-1-17改bug15174
    if (_model.uid == [AppDelegate shareDelegate].user.uid) {
        
    }else {
        
        UIButton* ButSign = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
        
        [ButSign setTitle:@"举报" forState:UIControlStateNormal];
        
        ButSign.titleLabel.font = [UIFont systemFontOfSize:15.0];
        
        [ButSign setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        [ButSign addTarget:self action:@selector(rightBarItemClick) forControlEvents:UIControlEventTouchUpInside];
        
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:ButSign];
    }
    
    
    
    _table.bdelegate = self;
    data = [[NSMutableArray alloc]init];
   
    [IQKeyboardManager sharedManager].enableAutoToolbar = NO;
    [IQKeyboardManager sharedManager].enable = NO;

    
    
    _inputView = [[UIView alloc]initWithFrame:CGRectMake(0, _searView.frame.origin.y, SCRE_WIDTH, _searView.frame.size.height)];
    NSLog(@"xhw->ViewDidLoad->_inputView.frame.origin.y->%f",_inputView.frame.origin.y);
    _inputView.backgroundColor = UIColorFromRGB(0xf3f3f3);
    _bqBtn = [[UIButton alloc]initWithFrame:CGRectMake(12, 12, 30, 26)];
    [_bqBtn setImage:[UIImage imageNamed:@"bq"] forState:UIControlStateNormal];
    [_bqBtn addTarget:self action:@selector(bqAction:) forControlEvents:UIControlEventTouchUpInside];
    [_inputView addSubview:_bqBtn];
    _hfText.layer.cornerRadius = 5;
    _hfText = [[UITextView alloc]initWithFrame:CGRectMake(50, 8, SCRE_WIDTH-(60+55), 30)];
    _hfText.delegate = self;
    [_inputView addSubview:_hfText];
    _senderBtn = [[UIButton alloc]initWithFrame:CGRectMake(SCRE_WIDTH-55, 8, 45, 30)];
    [_senderBtn setTitle:@"发送" forState:UIControlStateNormal];
    _senderBtn.titleLabel.font = [UIFont systemFontOfSize:14];
    [_senderBtn setBackgroundColor:UIColorFromRGB(0x263656)];
    [_senderBtn addTarget:self action:@selector(addHfAction:) forControlEvents:UIControlEventTouchUpInside];
    [_inputView addSubview:_senderBtn];
    _senderBtn.layer.cornerRadius = 4;
    _inputView.hidden = YES;
    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:_inputView];
    [self initData:0];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [[NSNotificationCenter defaultCenter]
     addObserver:self
     selector:@selector(scollTop:)
     name:@"scollTop"
     object:nil];
    
    [self addNotificaton];
}
-(void)scollTop:(NSNotification *)not{
    if (data.count!=0) {
            [_table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }
}
-(void)initData:(int)index{
    _table.backgroundColor = colorBG ;
    NSMutableDictionary *dic = [UserDefaults readUserDefaultObjectValueForKey:@"userLocation"];
    [dic setObject:[NSNumber numberWithInt:index] forKey:@"page"];
    if (_model) {
        [dic setObject:_model.id forKey:@"id"];
    }
    else {
        [dic setObject:_dynamicID forKey:@"id"];
    }
//    [dic setObject:_model.id forKey:@"id"];
    [[BusinessService shareInstance]getdynamic_detail:dic success:^(id result) {
        data = [_table result:result olddata:data index:index];
        
        
        if (notlabel) {
            [notlabel removeFromSuperview];
        }
        notlabel = (UILabel *)[_table notData];
        if (data.count == 0) {
            [self.view addSubview:notlabel];
        }
        else {
            _model = data[0];
        }
        [_table reloadData];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    NSLog(@"data.count->%lu",(unsigned long)data.count);
    return data.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
    return cell.frame.size.height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell =[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    //    cell.backgroundColor = colorBG;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    DTModel *model = [data objectAtIndex:indexPath.section];

    UIView *bgview= [[UIView alloc]initWithFrame:CGRectMake(0, 20, SCRE_WIDTH, 300)];
    //基础UI
    int b = [_table Basics:cell dtmodel:model bgview:bgview];
    //个人头像按钮
    UIButton *headbtn = [[UIButton alloc]initWithFrame:CGRectMake(20, 10, 45, 45)];
    headbtn.tag = indexPath.section;
    [headbtn addTarget:self action:@selector(toIndividualAction:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:headbtn];
    int file = 0;
    //附件
    if (model.attachment.count != 0) {
        file = [_table Attachment:cell dtmodel:model bgview:bgview];
        NSMutableDictionary *dic = [model.attachment lastObject];
        NSString *url = [dic objectForKey:@"path"];
        if (url.length>3) {
            url = [url substringFromIndex:url.length-3];
        }

        //附件按钮
        BaseButton *headbtn = [[BaseButton alloc]initWithFrame:CGRectMake(0, 45, SCRE_WIDTH, file)];
        headbtn.tag = indexPath.section;
        if ([url isEqualToString:@"mp4"]) {
            [headbtn setImage:[UIImage imageNamed:@"图标---视频播放"] forState:UIControlStateNormal];
        }
        [headbtn addTarget:self action:@selector(imgTouchAction:) forControlEvents:UIControlEventTouchUpInside];
        [bgview addSubview:headbtn];
    }
    //    //内容
    MLEmojiLabel * _emojiLabel = [MLEmojiLabel new];
    _emojiLabel.numberOfLines = 0;
    _emojiLabel.font = [UIFont systemFontOfSize:15.0f];
    _emojiLabel.backgroundColor = [UIColor clearColor];
    _emojiLabel.lineBreakMode = NSLineBreakByWordWrapping;
    _emojiLabel.textColor = [UIColor blackColor];
    
    _emojiLabel.textInsets = UIEdgeInsetsMake(0, 5, 0, 5);
    _emojiLabel.isNeedAtAndPoundSign = YES;
    _emojiLabel.disableEmoji = NO;
    _emojiLabel.disableThreeCommon = NO;
    _emojiLabel.delegate = self;
    
    _emojiLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentCenter;
    _emojiLabel.customEmojiRegex = @"\\[[emoji_[0-9]{1,3}]+\\]";
    _emojiLabel.customEmojiPlistName = @"expressionImage_custom.plist";
    if (!model.title) {
        [_emojiLabel setText:[NSString stringWithFormat:@"%@",@""]];
    }else {
        [_emojiLabel setText:[NSString stringWithFormat:@"%@",model.title]];
    }
    
    [bgview addSubview:_emojiLabel];
    CGRect g = _emojiLabel.frame;
    g.size.height = ([_emojiLabel preferredSizeWithMaxWidth:bgview.frame.size.width].height+10.0f*2);
    g.origin.y =  b+file;
    g.size.width = SCRE_WIDTH-10;
    g.origin.x = 0;
    _emojiLabel.frame = g;
    
    //头像高度+内容+图片高度
    int bottom = b+file+10 +g.size.height;
    
    if ([_emojiLabel.text trim].length==0) {
        bottom = b+file+10;
    }
    if(model.linkurl.length != 0){
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(15, bottom, bgview.frame.size.width - 30, 90)];
        view.layer.borderWidth = 0.5;
        view.layer.borderColor = colorBG.CGColor;
        [bgview addSubview:view];
        BaseButton  *btn = [[BaseButton alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
        [btn addTarget:self action:@selector(toweb:) forControlEvents:UIControlEventTouchUpInside];
        //        NSMutableDictionary *dic = [ValidateHelper GetHtmlImgOrTitle:model.linkurl];
        //        if (!dic) {
        //            UITextView *titletext = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, view.frame.size.width , 90)];
        //            titletext.text = @"该链接无法识别";
        //            titletext.userInteractionEnabled = NO;
        //            [view addSubview:titletext];
        //        }else{
        UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 70, 70)];
        [img sd_setImageWithURLs:[NSURL URLWithString:model.linkurl_img] placeholderImage:[UIImage imageNamed:@"notimgs"]];
        [view addSubview:img];
        
        UITextView *titletext = [[UITextView alloc]initWithFrame:CGRectMake(90, 5, view.frame.size.width - 90, 90)];
        titletext.text = model.linkurl_title;
        titletext.userInteractionEnabled = NO;
        [view addSubview:titletext];
        btn.name = model.linkurl;
        [view addSubview:btn];
        //        }
        bottom = bottom + 80;
        BaseButton *dizhi = [[BaseButton alloc]initWithFrame:CGRectMake(25, bottom+20, (SCRE_WIDTH)-90, 30)];
        dizhi.titleLabel.font = [UIFont systemFontOfSize:14];
//        [dizhi setTitle:model.cityname forState:UIControlStateNormal];
        [dizhi setTitle:model.addr forState:UIControlStateNormal];
        dizhi.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [dizhi setTitleColor:colorGrey forState:UIControlStateNormal];
        dizhi.model = model;
        [dizhi addTarget:self action:@selector(tomap:) forControlEvents:UIControlEventTouchUpInside];
        [bgview addSubview:dizhi];
        
        UIImageView *zidiimg = [[UIImageView alloc]initWithFrame:CGRectMake(10,dizhi.frame.origin.y+10, 9, 12.5)];
        zidiimg.image = [UIImage imageNamed:@"图标---位置"];
        [bgview addSubview:zidiimg];
    }else{
        BaseButton *dizhi = [[BaseButton alloc]initWithFrame:CGRectMake(25, bottom, (SCRE_WIDTH)-90, 30)];
        dizhi.titleLabel.font = [UIFont systemFontOfSize:14];
//        [dizhi setTitle:model.cityname forState:UIControlStateNormal];
        [dizhi setTitle:model.addr forState:UIControlStateNormal];
        dizhi.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        [dizhi setTitleColor:colorGrey forState:UIControlStateNormal];
        dizhi.model = model;
        [dizhi addTarget:self action:@selector(tomap:) forControlEvents:UIControlEventTouchUpInside];
        [bgview addSubview:dizhi];
        
        UIImageView *zidiimg = [[UIImageView alloc]initWithFrame:CGRectMake(10,dizhi.frame.origin.y+10, 9, 12.5)];
        zidiimg.image = [UIImage imageNamed:@"图标---位置"];
        [bgview addSubview:zidiimg];
    }
    
    bottom = bottom + 43;


    UIButton *sharebtn = [[UIButton alloc]initWithFrame:CGRectMake(85, bottom, 40, 40)];
    [sharebtn setImage:[UIImage imageNamed:@"图标---转发"] forState:UIControlStateNormal];
    //    [sharebtn setTitle:model.sharecount forState:UIControlStateNormal];
    [sharebtn setTitleColor:colorGrey forState:UIControlStateNormal];
    sharebtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [sharebtn addTarget:self action:@selector(fenxiang:) forControlEvents:UIControlEventTouchUpInside];
    sharebtn.indexPath = indexPath;
    sharebtn.tag = indexPath.section;

    [bgview addSubview:sharebtn];
    
    UIButton *zanbtn = [[UIButton alloc]initWithFrame:CGRectMake(5, bottom, 40, 40)];
    [zanbtn setImage:[UIImage imageNamed:@"图标---喜欢"] forState:UIControlStateNormal];
    zanbtn.tag = indexPath.section;
    if ([model.iszan intValue] == 1) {
        [zanbtn setImage:[UIImage imageNamed:@"图标---赞"] forState:UIControlStateNormal];
    }else{
        [zanbtn setImage:[UIImage imageNamed:@"图标---喜欢"] forState:UIControlStateNormal];
    }
    [zanbtn addTarget:self action:@selector(praiseAction:) forControlEvents:UIControlEventTouchUpInside];
    [bgview addSubview:zanbtn];
    
    BaseButton *plbtn = [[BaseButton alloc]initWithFrame:CGRectMake(45, bottom, 40, 40)];
    [plbtn setImage:[UIImage imageNamed:@"图标---评论"] forState:UIControlStateNormal];
    [plbtn setTitleColor:colorGrey forState:UIControlStateNormal];
    plbtn.titleLabel.font = [UIFont systemFontOfSize:12];
    plbtn.tag = indexPath.section;
    //    [plbtn setTitle:model.commentcount forState:UIControlStateNormal];
    [plbtn addTarget:self action:@selector(toReplyAction:) forControlEvents:UIControlEventTouchUpInside];
    [bgview addSubview:plbtn];
    
    UILabel *distance = [[UILabel alloc]initWithFrame:CGRectMake((SCRE_WIDTH)-90, bottom,80, 30)];
    distance.text = [ValidateHelper DistanceFormat:model.distance];
    distance.font = [UIFont systemFontOfSize:14];
    distance.textColor = colorGrey;
    distance.textAlignment = NSTextAlignmentRight;
    [bgview addSubview:distance];
    
    //按钮分割线
    UILabel *ine = [[UILabel alloc]initWithFrame:CGRectMake(0, bottom + 40,SCRE_WIDTH,0.5)];
    ine.backgroundColor = colorBG;
    [bgview addSubview:ine];
    
    UILabel *zanlable = [[UILabel alloc]initWithFrame:CGRectMake(15, bottom + 40, SCRE_WIDTH-20, 30)];
    zanlable.text = [NSString stringWithFormat:@"❤︎%@次赞",model.zancount];
    zanlable.font = [UIFont systemFontOfSize:13];
    [bgview addSubview:zanlable];
    // 留言
    int ly = zanlable.frame.size.height + zanlable.frame.origin.y;
    int y = ly;
    int liuh=0;
    //    if (zkindex==indexPath.section+1) {
    if (model.commentlist.count!=0) {
        liuh=0;
        y = ly;
        for (int i = 0; i<model.commentlist.count; i++) {
            NSLog(@"log3");
            NSMutableDictionary *dic = [model.commentlist objectAtIndex:i];
            NSLog(@"log3");
//            if (i>=3) {
//                BaseButton *btn = [[BaseButton alloc]initWithFrame:CGRectMake(10, y-10, 60, 30)];
//                [btn addTarget:self action:@selector(toxiangq:) forControlEvents:UIControlEventTouchUpInside];
//                [btn setTitle:@"查看更多" forState:UIControlStateNormal];
//                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//                btn.titleLabel.font = [UIFont systemFontOfSize:12];
//                [bgview addSubview:btn];
//                btn.model = model;
//                y = y + 30;
//                break;
//            }else{
                int x =0;
                NSString *rname = [dic objectForKey:@"reply_nickname"];
                NSString *nickname = [dic objectForKey:@"nickname"];
                
                
                //                UIImageView *head = [[UIImageView alloc]initWithFrame:CGRectMake(10+x, y, 35, 35)];
                //                [head sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"headsmall"]]
                //                        placeholderImage:[UIImage imageNamed:@"mrtx"]];
                //                head.layer.cornerRadius = 35/2;
                //                head.clipsToBounds = YES;
                CGSize n = [ValidateHelper sizeOfText:![rname isEqualToString:nickname]?[NSString stringWithFormat:@"%@回复%@:",[dic objectForKey:@"nickname"],[dic objectForKey:@"reply_nickname"]]:[NSString stringWithFormat:@"%@:",[dic objectForKey:@"nickname"]]  theFont:[UIFont systemFontOfSize:13]];
                
                //                [bgview addSubview:head];
                BaseButton *btn = [[BaseButton alloc]initWithFrame:CGRectMake(10, y,n.width+10, 30)];
                [btn addTarget:self action:@selector(SingleReplyActino:) forControlEvents:UIControlEventTouchUpInside];
                btn.tag = indexPath.section;
                btn.index = i;
                btn.titleLabel.textAlignment = NSTextAlignmentRight;
                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                NSString *titlename =![rname isEqualToString:nickname]?[NSString stringWithFormat:@"%@回复%@:",[dic objectForKey:@"nickname"],[dic objectForKey:@"reply_nickname"]]:[NSString stringWithFormat:@"%@:",[dic objectForKey:@"nickname"]];
                //                [btn setTitle:titlename forState:UIControlStateNormal];
                
                btn.titleLabel.font = [UIFont systemFontOfSize:14];
                [bgview addSubview:btn];
                
                
                MLEmojiLabel * _emojiLabel = [MLEmojiLabel new];
                _emojiLabel.numberOfLines = 0;
                _emojiLabel.font = [UIFont systemFontOfSize:14.0f];
                _emojiLabel.backgroundColor = [UIColor clearColor];
                _emojiLabel.lineBreakMode = NSLineBreakByWordWrapping;
                _emojiLabel.textColor = [UIColor blackColor];
                
                _emojiLabel.textInsets = UIEdgeInsetsMake(0, 0, 0, 0);
                _emojiLabel.isNeedAtAndPoundSign = YES;
                _emojiLabel.disableEmoji = NO;
                _emojiLabel.disableThreeCommon = YES;
                _emojiLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentCenter;
                _emojiLabel.customEmojiRegex = @"\\[[emoji_[0-9]{1,3}]+\\]";
                _emojiLabel.customEmojiPlistName = @"expressionImage_custom.plist";
                [_emojiLabel setText:[NSString stringWithFormat:@"%@%@",titlename,[dic objectForKey:@"content"]]];
                int  h =   SCRE_WIDTH - 20;
                
                CGSize size = [_emojiLabel preferredSizeWithMaxWidth:h];
                
                CGRect g = _emojiLabel.frame;
                g.size.height = ([_emojiLabel preferredSizeWithMaxWidth:size.width].height+10.0f);
                g.origin.y = btn.frame.origin.y - 3;
                g.size.width = SCRE_WIDTH - 20;
                g.origin.x = 15;
                _emojiLabel.frame = g;
                [bgview addSubview:_emojiLabel];
                y = y + _emojiLabel.frame.size.height;
//            }
        }
        liuh =  y - ly;
    }
    //    }
    CGSize s =[ValidateHelper sizeOfText:distance.text theFont:[UIFont systemFontOfSize:14]];
    CGRect di = distance.frame;
    di.size.width = s.width +10;
    di.origin.x = (SCRE_WIDTH) - s.width -20;
    distance.frame = di;
    
    CGRect bg = bgview.frame;
    bg.size.height = zanlable.frame.size.height+zanlable.frame.origin.y + liuh;
    bgview.frame = bg;
    
    CGRect cl =  cell.frame;
    cl.size.height = bg.size.height+30;
    cell.frame = cl;
    return cell;
}
#pragma  mark URL 跳转
-(void)mlEmojiLabel:(MLEmojiLabel *)emojiLabel didSelectLink:(NSString *)link withType:(MLEmojiLabelLinkType)type{
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"toadview" object:link];
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"toweb" object:link];
}
-(void)tomap:(BaseButton *)btn{
    DTModel * xhwtestModel = (DTModel *)btn.model;
    NSLog(@"熊宏伟->DetailsVC->tomap->model.address->%@",xhwtestModel.addr);
    NSLog(@"熊宏伟->DetailsVC->tomap->model.lat->%@",xhwtestModel.lat);
    NSLog(@"熊宏伟->DetailsVC->tomap->model.lng->%@",xhwtestModel.lng);
    [[NSNotificationCenter defaultCenter]postNotificationName:@"tomap" object:btn.model];
    
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    DTModel *model = [data objectAtIndex:collectionView.tag];

    return  model.zanlist.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    NSLog(@"log5");
    DTModel *model = [data objectAtIndex:collectionView.tag];
    NSMutableDictionary *dic = [model.zanlist objectAtIndex:indexPath.row];
    NSLog(@"log5");
    zanCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"zanCell" forIndexPath:indexPath];
    UIImageView *head = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 35, 35)];
    head.layer.cornerRadius = 35/2;
    head.clipsToBounds = YES;
    [head sd_setImageWithURL:[NSURL URLWithString:[dic objectForKey:@"headsmall"]]
            placeholderImage:[UIImage imageNamed:@"mrtx"]];
    [cell.contentView addSubview:head];
    
    UIImageView *bq = [[UIImageView alloc]initWithFrame:CGRectMake(35-18, 35-20, 18, 15)];
    bq.image = [UIImage imageNamed:[dic objectForKey:@"content"]];
    [head addSubview:bq];
    
    return cell;
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0, 5, 0, 5);
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    CGSize size = CGSizeMake(32, 32);
    return size;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
#pragma mark 链接跳转
-(void)toweb:(BaseButton *)btn{
    [[NSNotificationCenter defaultCenter ]postNotificationName:@"toadview" object:btn.name];
}

- (void)addNotificaton {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textChanged:) name:UITextViewTextDidChangeNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardChanged:) name:UIKeyboardWillChangeFrameNotification object:nil];
}


- (void)xhwInitBottomInput {
    _viewBottom.hidden = false;
    for (UIView *view in _viewBottom.subviews) {
        [view removeFromSuperview];
    }
    
    UIView *viewBox = [[UIView alloc] initWithFrame:CGRectMake(5, 3.5, ScreenWidth - 5 - 96, 49 - 7)];
    viewBox.tag = 11;
    viewBox.backgroundColor = [UIColor whiteColor];
    viewBox.layer.cornerRadius = 4;
    [_viewBottom addSubview:viewBox];
    
    UITextView *txt = [[UITextView alloc] initWithFrame:CGRectMake(5, 3, viewBox.width - 10, viewBox.frame.size.height - 6) textContainer:nil];
    txt.tag = 10;
    txt.delegate = self;
    txt.font = [UIFont systemFontOfSize:15];
    txt.backgroundColor = [UIColor whiteColor];
    txt.returnKeyType = UIReturnKeySend;
    txt.layoutManager.allowsNonContiguousLayout = NO;
    [viewBox addSubview:txt];
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.tag = 12;
    btn.backgroundColor = [UIColor clearColor];
    [btn setImage:[UIImage imageNamed:@"bq"] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:@"bq"] forState:UIControlStateHighlighted];
    
    btn.frame = CGRectMake(viewBox.frame.origin.x + viewBox.frame.size.width, 0, ScreenWidth - (viewBox.frame.origin.x + viewBox.frame.size.width), 49);
    [btn addTarget:self action:@selector(btnFaceClick:) forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font = [UIFont systemFontOfSize:15];
    [_viewBottom addSubview:btn];
}

- (void)btnFaceClick:(UIButton *)sender {
    _shouldChangeBottom = NO;
    [self.view endEditing:YES];
    _shouldChangeBottom = true;
//    if (!_tapGestureRecognizer) {
//        _tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRespond:)];
//
//    }
//    NSArray * GesArr = self.view.gestureRecognizers;
//    if (GesArr) {
//        if (GesArr.count == 0) {
//            [self.view addGestureRecognizer:_tapGestureRecognizer];
//        }
//    }
//    else {
//        [self.view addGestureRecognizer:_tapGestureRecognizer];
//    }
    if ([sender.titleLabel.text isEqualToString:@"发送"]) {
        if ([self.viewBottom viewWithTag:10]) {
            UITextView *textView = [self.viewBottom viewWithTag:10];
            if (textView.text.length != 0) {
                
                if([textView.text trim].length > 300){
                    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"超过%d个字符",(int)[_hfText.text trim].length - 300] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
                    [alert show];
                    return;
                }
                huifumsg = _model;
                NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
               
                UITextView *xhwTextView = (UITextView *)[_viewBottom viewWithTag:10];
                [dic setObject:[EmotionInputView encodeMessageEmoji:[xhwTextView.textStorage getPlainString]]  forKey:@"content"];
                

                if (isReplySingle == 0) {
                    [dic setObject:huifumsg.id forKey:@"id"];
                    [dic setObject:huifumsg.uid forKey:@"replyuid"];
                }else{
                    [dic setObject:huifumsg.id forKey:@"id"];
                    [dic setObject:[ReplySingle objectForKey:@"uid"] forKey:@"replyuid"];
                }
                [[BusinessService shareInstance]addreply:dic success:^(id result) {
                    _table.refresh = YES;
                    [_table  headerRereshing];
                } failure:^(id result) {
                    [SVProgressHUD showErrorWithStatus:result];
                }];
                
                self.isHidenViewBottom = YES;
                
                [self tapRespond:nil];
                textView.text = @"";
                [textView resignFirstResponder];
                [self textChanged:nil];
            }
            else {
                [SVProgressHUD showWithStatus:@"评论内容不能为空"];
            }
        }
    }
    else {
        sender.selected = !sender.selected;
        if (sender.selected) {
            [sender setImage:nil forState:UIControlStateNormal];
            [sender setImage:nil forState:UIControlStateHighlighted];
            [sender setTitle:@"发送" forState:UIControlStateNormal];
            [sender setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
            [UIView animateWithDuration:0.25 animations:^{
                
                CGRect temp1 = self.endKeyboardRect;
                CGRect temp2 = self.emojiView.frame;
                temp1.size.height = temp2.size.height;
                self.endKeyboardRect = temp1;

                [self changeBottomInput];
                self.emojiView.frame = CGRectMake(self.emojiView.frame.origin.x, self.viewBottom.frame.origin.y + self.viewBottom.frame.size.height, self.emojiView.frame.size.width, self.emojiView.frame.size.height);
            }];
        }
        else {
            [sender setImage:[UIImage imageNamed:@"bq"] forState:UIControlStateNormal];
            [sender setImage:[UIImage imageNamed:@"bq"] forState:UIControlStateHighlighted];
            [sender setTitle:@"" forState:UIControlStateNormal];
            [UIView animateWithDuration:0.25 animations:^{
                [self changeBottomInput];
                self.emojiView.frame = CGRectMake(self.emojiView.frame.origin.x, self.view.frame.size.height, self.emojiView.frame.size.width, self.emojiView.frame.size.height);
            }];
        }
    }
}

- (void)tapRespond:(UIGestureRecognizer *)gesture {
    
    NSLog(@"tapRespond->gestrue:%@",gesture);
    
    _isHidenViewBottom = YES;
    
    if ([self.viewBottom viewWithTag:10]) {
        UITextView *txt = [self.viewBottom viewWithTag:10];
        txt.text = @"";
        [self textChanged:nil];
    }
    [self.view endEditing:YES];
    self.endKeyboardRect = CGRectZero;
    [UIView animateWithDuration:0.25 animations:^{
        self.emojiView.frame = CGRectMake(self.emojiView.frame.origin.x, self.view.frame.size.height, self.emojiView.frame.size.width, self.emojiView.frame.size.height);
        NSLog(@"tapRespond->self.view.frame.size.height:%f",self.view.frame.size.height);
        NSLog(@"tapRespond->_table.frame.origin.y:%f",_table.frame.origin.y);
        NSLog(@"tapRespond->self.viewBottom.frame.size.height:%f",self.viewBottom.frame.size.height);
        NSLog(@"tapRespond->self.endKeyboardRect.size.height:%f",self.endKeyboardRect.size.height);
//        _table.frame = CGRectMake(0, _table.frame.origin.y, _table.frame.size.width, self.view.frame.size.height - _table.frame.origin.y - self.viewBottom.frame.size.height - self.endKeyboardRect.size.height);
         _table.frame = CGRectMake(0, _table.frame.origin.y, _table.frame.size.width, self.view.frame.size.height - _table.frame.origin.y - self.endKeyboardRect.size.height);
        
        self.viewBottom.frame = CGRectMake(0, _table.frame.origin.y + _table.frame.size.height, self.viewBottom.frame.size.width, self.viewBottom.frame.size.height);
        NSLog(@"测试点击发送之后_viewBottom.frame:%f",_viewBottom.frame.origin.y);
    }];
}

- (void)textChanged:(NSNotification *)notication {
    if ([self.viewBottom viewWithTag:10]) {
        UITextView *txt = [self.viewBottom viewWithTag:10];
        if (txt.text.length == 0) {
            CGSize temp = txt.contentSize;
            temp.height = 34;
            txt.contentSize = temp;
        }
        if (txt.contentSize.height <= 70) {
            if (txt.contentSize.height < 34) {
                CGSize temp = txt.contentSize;
                temp.height = 34;
                txt.contentSize = temp;
            }
            _viewBottom.frame = CGRectMake(_viewBottom.frame.origin.x, _viewBottom.frame.origin.y, _viewBottom.frame.size.width, txt.contentSize.height + 15);
            NSLog(@"佛氨基酚:动态详细->textChanged方法->txt.contentSize.height->%f",txt.contentSize.height);
            NSLog(@"佛氨基酚:动态详细->textChanged方法->viewBottom.y->%f",_viewBottom.frame.origin.y);
            NSLog(@"佛氨基酚:动态详细->textChanged方法->viewBottom.height->%f",_viewBottom.frame.size.height);
            UIView * viewBox = [_viewBottom viewWithTag:11];
            viewBox.frame = CGRectMake(viewBox.frame.origin.x, (_viewBottom.height-txt.contentSize.height-6)/2.0, viewBox.frame.size.width, txt.contentSize.height + 6);
            txt.frame = CGRectMake(txt.frame.origin.x, 3, txt.width, txt.contentSize.height);
            UIButton *btn = [_viewBottom viewWithTag:12];
            btn.frame = CGRectMake(btn.frame.origin.x, 0, btn.frame.size.width, btn.frame.size.height);
            [UIView animateWithDuration:0.25 animations:^{
                [self changeBottomInput];
                

            }];
        }
    }
}

- (void)keyBoardChanged:(NSNotification *)notication {
//    if ([self.viewBottom viewWithTag:10]) {
//        UITextView *txt = [self.viewBottom viewWithTag:10];
//        txt.contentOffset = CGPointMake(0, txt.contentSize.height-txt.frame.size.height);
//    }
    NSDictionary *userInfo = notication.userInfo;
    double duration = [userInfo[UIKeyboardAnimationCurveUserInfoKey] doubleValue];
    
    NSLog(@"哈哈哈测试动画时间:%f",duration);
    self.endKeyboardRect = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    if (self.endKeyboardRect.origin.y == SCRE_HEIGHT) {
        self.endKeyboardRect = CGRectZero;
        if (_tapGestureRecognizer) {
            NSArray *gesArr = self.view.gestureRecognizers;
            if (gesArr) {
                [self.view removeGestureRecognizer:_tapGestureRecognizer];
            }
        }
    }
    else {
//        if (!_tapGestureRecognizer) {
//            _tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapRespond:)];
//        }
//        NSArray * gesArr = self.view.gestureRecognizers;
//        if (gesArr) {
//            if (gesArr.count == 0) {
//                [self.view addGestureRecognizer:_tapGestureRecognizer];
//            }
//        }
//        else {
//            [self.view addGestureRecognizer:_tapGestureRecognizer];
//        }
    }
    
    [UIView animateWithDuration:0.25 animations:^{
        [self changeBottomInput];
        
        if (self.endKeyboardRect.size.height == 0) {
            if (_type == 0) {
                
            }
            else {
                [self xhwInitBottomInput];
            }
            self.emojiView.frame = CGRectMake(self.emojiView.frame.origin.x, self.view.frame.size.height, self.emojiView.frame.size.width, self.emojiView.frame.size.height);
        }
        
    }];
}

- (void)changeBottomInput {
    if (_shouldChangeBottom) {
//        _table.frame = CGRectMake(0, _table.frame.origin.y, _table.frame.size.width, self.view.frame.size.height - _table.frame.origin.y - _viewBottom.frame.size.height - self.endKeyboardRect.size.height);
        _table.frame = CGRectMake(0, _table.frame.origin.y, _table.frame.size.width, self.view.frame.size.height - _table.frame.origin.y - self.endKeyboardRect.size.height);
        _viewBottom.frame = CGRectMake(0, _table.frame.origin.y + _table.frame.size.height, _viewBottom.frame.size.width, _viewBottom.frame.size.height);
        NSLog(@"changeBottomInput->viewbottom.y:%f",_viewBottom.frame.origin.y);
        self.viewBottom.hidden = NO;
        if (_isHidenViewBottom) {
            self.viewBottom.hidden = YES;
        }
    }
}



-(void)toReplyAction:(BaseButton *)btn{
    self.viewBottom.hidden = false;
    self.isHidenViewBottom = false;
    [self.view endEditing:YES];
    [self xhwInitBottomInput];
    UITextView * xhwTextView = [self.viewBottom viewWithTag:10];
    [xhwTextView becomeFirstResponder];
    
    
    
    
//    huifumsg = [data objectAtIndex:btn.tag];
//    _inputView.tag = btn.tag;
//    _inputView.hidden = NO;
////    _hfText.text = @"评论";
//    isUp = YES;  //xhw2018-1-31加
//    [_hfText becomeFirstResponder];
};
#pragma mark -点击了评论按钮
- (IBAction)replyAction:(BaseButton *)sender {
    [zanview removeFromSuperview];
    
    huifumsg = _model;
    _inputView.tag = sender.tag;
    _inputView.hidden = NO;
//    _hfText.text = @"评论";
    isUp = YES;  //xhw2018-1-31加
    [_hfText becomeFirstResponder];
    
}
#pragma  mark 分享
-(void)fenxiang:(BaseButton *)btn{
    NSLog(@"log6");
    DTModel *model = [data objectAtIndex:btn.indexPath.row];
    NSLog(@"log6");
    UIActionSheet * editActionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
    editActionSheet.tag = btn.tag;
    [editActionSheet addButtonWithTitle:@"微博"];
    [editActionSheet addButtonWithTitle:@"微信好友"];
    [editActionSheet addButtonWithTitle:@"朋友圈"];
    [editActionSheet addButtonWithTitle:@"QQ空间"];
    [editActionSheet addButtonWithTitle:@"QQ"];
    [editActionSheet addButtonWithTitle:@"取消"];
    editActionSheet.cancelButtonIndex = editActionSheet.numberOfButtons - 1;
    [editActionSheet showFromTabBar:self.tabBarController.tabBar];
    editActionSheet.delegate = self;
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    
    if (buttonIndex + 1 >= actionSheet.numberOfButtons ) {
        return;
    }
    NSInteger snsName = UMSocialPlatformType_QQ;
    if (buttonIndex == 0) {
        snsName = UMSocialPlatformType_Sina;
    }else if (buttonIndex == 1){
        snsName = UMSocialPlatformType_WechatSession;
    }else if (buttonIndex == 2){
        snsName = UMSocialPlatformType_WechatTimeLine;
    }else if (buttonIndex == 3){
        snsName = UMSocialPlatformType_Qzone;
    }else if (buttonIndex == 4){
        snsName = UMSocialPlatformType_QQ;
    }
    NSLog(@"log7");
    DTModel *model = [data objectAtIndex:actionSheet.tag];
    NSLog(@"log7");
    UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
    UIImage *shareImage = [UIImage imageNamed:@"icon"];
    [[AppDelegate shareDelegate]refuser:_model.uid success:^(id as) {
        LoginResponseModel *user = (LoginResponseModel *)as;
        UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"一米社交" descr:[NSString stringWithFormat:@"一米社交的[%@]发布的动态",user.nickname] thumImage:shareImage];
        //设置网页地址
        NSString *linkUrl = [NSString stringWithFormat:@"%@?type=1&id=%@",sharepageurl,model.id];
        shareObject.webpageUrl = linkUrl;
        
        //分享消息对象设置分享内容对象
        messageObject.shareObject = shareObject;
        
        
        [[UMSocialManager defaultManager] shareToPlatform:snsName messageObject:messageObject currentViewController:self completion:^(id result, NSError *error) {
            if (error) {
                UMSocialLogInfo(@"************Share fail with error %@*********",error);
            }
            else {
                if ([result isKindOfClass:[UMSocialShareResponse class]]) {
                    UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:@"成功" message:@"分享成功" delegate:nil cancelButtonTitle:@"好" otherButtonTitles:nil];
                    [alertView show];
                    NSMutableDictionary *dic= [[NSMutableDictionary alloc]init];
                    [dic setObject:@"1" forKey:@"type"];
                    [dic setObject:_model.id forKey:@"content"];
                    [dic setObject:@"1" forKey:@"isopen"];
                    
                    [dic setObject:@"0" forKey:@"isweibo"];
                    [dic setObject:@"0" forKey:@"isweixin"];
                    [dic setObject:@"0" forKey:@"isweixinquan"];
                    [dic setObject:@"0" forKey:@"isqqzone"];
                    [dic setObject:@"0" forKey:@"isqq"];
                    
                    if (buttonIndex == 0) {
                        [dic setObject:@"1" forKey:@"isweibo"];
                    }else if (buttonIndex == 1){
                        [dic setObject:@"1" forKey:@"isweixin"];
                    }else if (buttonIndex == 2){
                        [dic setObject:@"1" forKey:@"isweixinquan"];
                    }else if (buttonIndex == 3){
                        [dic setObject:@"1" forKey:@"isqqzone"];
                    }else if (buttonIndex == 4){
                        [dic setObject:@"1" forKey:@"isqq"];
                    }
                    [dic setObject:@"1" forKey:@"isopen"];
                    [[BusinessService shareInstance]sharerecord:dic success:^(id result) {
                        
                    } failure:^(id result) {
                        
                    }];
                }
                else {
                    UMSocialLogInfo(@"response data is %@",result);
                }
            }
        }];
    }];
}



#pragma mark 图片详情 这里怎么获取这个人的相册列表啊
-(void)imgTouchAction:(BaseButton *)sender{
    NSLog(@"走到点击图片了");
    if (data.count != 0) {
        NSLog(@"log8");
        DTModel *msg = [data objectAtIndex:sender.tag];
        NSLog(@"log8");
        
        NSMutableArray  *arM = [NSMutableArray array];

        for (NSDictionary *xwDic in self.xwPicArray ) {
            
            //        if ([self.model.uid isEqualToString:xwDic[@"id"]]) {
            
            [arM addObject:xwDic[@"array"]];
            
            //        }
            
            
        }
        
        NSString *url;
        
        if (msg.attachment.count != 0) {
            NSMutableDictionary *dic = [msg.attachment lastObject];
            url = [dic objectForKey:@"path"];
            
            if (![ValidateHelper isHttpHead:url]) {
                
                url = [NSString stringWithFormat:@"%@%@",img_Url,url];
            }
            if ([dic objectForKey:@"path"]) {
                
                if([url rangeOfString:@"mp4"].location !=NSNotFound){//_roaldSearchText
                    
                    [self Plays:url];
                    
                }else{
                    
                    //            [self EnlargePicAction:msg];
                    NSLog(@"arM.count->%lul",(unsigned long)arM.count);
                    [arM addObject:url]; //xhw2018-2-8加
                    [self showPicWithArray:arM currentPath:[dic objectForKey:@"path"]];
                }
                
            }
        }
    }
    NSLog(@"说明不是这里的问题");
}

#pragma mark 视频播放
-(void)Plays:(NSString *)not{
    [zanview removeFromSuperview];
    NSURL *url = [NSURL URLWithString:not];
    moviePlayer = [ValidateHelper bofang:url];
    [self.view addSubview:moviePlayer.view];
    self.navigationController.navigationBarHidden = YES;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playVideoFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
}
#pragma  mark 视频播放注销监听
- (void)playVideoFinished:(NSNotification *)theNotification{
    // 取消监听
    self.navigationController.navigationBarHidden = NO;
    [[NSNotificationCenter defaultCenter]
     removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
    // 将视频视图从父视图中删除
    [moviePlayer.view removeFromSuperview];
}

#pragma mark -- 谢为修改 图片放大
- (void)showPicWithArray:(NSArray *)array currentPath:(NSString *)currentPath{
 
    NSLog(@"走到图片放大了");
    [zanview removeFromSuperview];
    
    array = [[NSSet setWithArray:array] allObjects];
    
    NSMutableArray  *imgdata = [[NSMutableArray alloc]init];
    
//    DTModel *msg = not;
    NSInteger index = 0;
    for (int i = 0; i < array.count; i ++) {
        NSString *url;
        
        ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
        
        
        if (![ValidateHelper isHttpHead:array[i]]) {
            
            url = [NSString stringWithFormat:@"%@%@",img_Url,array[i]];
        }
        if ([array[i] isEqualToString:currentPath]) {
            index = i;
        }
        
        photo.photoURL = [NSURL URLWithString:url];
        
        [imgdata addObject:photo];
    }
    /*for (NSString  *dic in array) {
        
        NSString *url;
        
        ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
        
        
        if (![ValidateHelper isHttpHead:dic]) {
            
            url = [NSString stringWithFormat:@"%@%@",img_Url,dic];
        }
        
        photo.photoURL = [NSURL URLWithString:url];
        
        [imgdata addObject:photo];
    }*/

    
    // 图片游览器
    ZLPhotoPickerBrowserViewController *pickerBrowser = [[ZLPhotoPickerBrowserViewController alloc] init];
    // 数据源/delegate
    //    pickerBrowser.delegate = self;
    pickerBrowser.status = UIViewAnimationAnimationStatusFade;
    
    // 数据源可以不传，传photos数组 photos<里面是ZLPhotoPickerBrowserPhoto>
    NSLog(@"log9->imgdata.count:%lu",(unsigned long)imgdata.count);
    pickerBrowser.photos = imgdata;
    NSLog(@"log9");
    // 是否可以删除照片
    pickerBrowser.editing = NO;
    // 当前选中的值
    NSLog(@"log10");
    pickerBrowser.currentIndexPath = [NSIndexPath indexPathForRow:index inSection:0];
    NSLog(@"log10");
    NSLog(@"图片放大index:%ld",(long)index);
    // 展示控制器
    [pickerBrowser showPickerVc:self];
    
    NSLog(@"说明不是图片放大的问题");
    
}

#pragma mark 图片放大
-(void)EnlargePicAction:(DTModel *)not{
    
    [zanview removeFromSuperview];
    
    NSMutableArray  *imgdata = [[NSMutableArray alloc]init];
    
    DTModel *msg = not;
    
    for (int i= 0;i<msg.attachment.count; i++) {
        
        ZLPhotoPickerBrowserPhoto *photo = [[ZLPhotoPickerBrowserPhoto alloc] init];
        NSLog(@"log1");
        NSString *url = [[msg.attachment objectAtIndex:i] objectForKey:@"path"];
        NSLog(@"log1");
        if (![ValidateHelper isHttpHead:url]) {
            
            url = [NSString stringWithFormat:@"%@%@",img_Url,url];
        }
        
         photo.photoURL = [NSURL URLWithString:url];
        
        [imgdata addObject:photo];
    }
    
    // 图片游览器
    ZLPhotoPickerBrowserViewController *pickerBrowser = [[ZLPhotoPickerBrowserViewController alloc] init];
    // 数据源/delegate
    //    pickerBrowser.delegate = self;
    pickerBrowser.status = UIViewAnimationAnimationStatusFade;
    
    // 数据源可以不传，传photos数组 photos<里面是ZLPhotoPickerBrowserPhoto>
    pickerBrowser.photos = imgdata;
    
    // 是否可以删除照片
    pickerBrowser.editing = NO;
    // 当前选中的值
    pickerBrowser.currentIndexPath = [NSIndexPath indexPathForRow:0 inSection:0];
    // 展示控制器
    [pickerBrowser showPickerVc:self];
    
}
#pragma mark 单人回复
-(void)SingleReplyActino:(BaseButton *)btn{
    [zanview removeFromSuperview];
    isReplySingle = 1;
    huifumsg = _model;
    ReplySingle = btn.model;
    if ([AppDelegate shareDelegate].user.uid == [ReplySingle objectForKey:@"uid"]) {
        [SVProgressHUD showErrorWithStatus:@"不能回复自己评论"];
        return;
    }
    _hfText.text = @"回复";
    _inputView.tag = btn.tag;
    _inputView.hidden = NO;
    [_hfText becomeFirstResponder];
}
- (EmotionInputView *)emojiView {
    if (!_emojiView) {
        _emojiView = [[EmotionInputView alloc]initWithDelegate:self];
        _emojiView.backgroundColor = [UIColor whiteColor];
        _emojiView.frame = CGRectMake(0, SCRE_HEIGHT-192, SCRE_WIDTH, 192);
    }
    return _emojiView;
}
- (void)emotionInputView:(id)sender output:(NSString *)str {
//    if (_hfText) {
//        _hfText.text = [NSString stringWithFormat:@"%@%@",_hfText.text,[EmotionInputView emojiText4To5:str]];
//    }
    if ([self.viewBottom viewWithTag:10]) {
        UITextView *txt = [self.viewBottom viewWithTag:10];
        txt.text = [NSString stringWithFormat:@"%@%@",txt.text,[EmotionInputView emojiText4To5:str]];
        [self textChanged:nil];
    }
}

#pragma mark 添加回复
- (IBAction)addHfAction:(UIButton *)sender {
    if([_hfText.text trim].length > 300){
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:[NSString stringWithFormat:@"超过%d个字符",(int)[_hfText.text trim].length - 300] delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return;
    }
//    _inputView.hidden = YES;
//    [self.view endEditing:YES];
//    [XHWEmojiView removeFromSuperview];
//    [self up:NO];
    isUp = NO;
    if (self.emojiView) {
        [self up:NO];
        [self.emojiView removeFromSuperview];
    }
    [self.view endEditing:YES];
    [_hfText resignFirstResponder];
    self.isShowEmojiView = NO;
    self.emojiView.hidden = YES;
    NSLog(@"addHfAction调用了up方法");
    huifumsg = _model;
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
//    [dic setObject:[_hfText.textStorage getPlainString]  forKey:@"content"];
    [dic setObject:[EmotionInputView encodeMessageEmoji:[_hfText.textStorage getPlainString]]  forKey:@"content"];
    if (isReplySingle == 0) {
        [dic setObject:huifumsg.id forKey:@"id"];
        [dic setObject:huifumsg.uid forKey:@"replyuid"];
    }else{
        [dic setObject:huifumsg.id forKey:@"id"];
        [dic setObject:[ReplySingle objectForKey:@"uid"] forKey:@"replyuid"];
    }
    [[BusinessService shareInstance]addreply:dic success:^(id result) {
        _hfText.text = nil;
        _table.refresh = YES;
        [_table  headerRereshing];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}
- (void)xhwSendCommmet {
    
    self.isHidenViewBottom = YES;
     huifumsg = _model;
    
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    //    [dic setObject:[_hfText.textStorage getPlainString]  forKey:@"content"];
    if ([_viewBottom viewWithTag:10]) {
        UITextView * xhwTextView = (UITextView *)[_viewBottom viewWithTag:10];
        [dic setObject:[EmotionInputView encodeMessageEmoji:[xhwTextView.textStorage getPlainString]]  forKey:@"content"];
    }

    if (isReplySingle == 0) {
        [dic setObject:huifumsg.id forKey:@"id"];
        [dic setObject:huifumsg.uid forKey:@"replyuid"];
    }else{
        [dic setObject:huifumsg.id forKey:@"id"];
        [dic setObject:[ReplySingle objectForKey:@"uid"] forKey:@"replyuid"];
    }
    [[BusinessService shareInstance]addreply:dic success:^(id result) {
        _table.refresh = YES;
        [_table  headerRereshing];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
}

-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    
    if ([text isEqualToString:@"\n"]) {
        if (textView.text.length != 0) {
            NSLog(@"发送");
            [self xhwSendCommmet];
            textView.text = @"";
            [textView resignFirstResponder];
            [self textChanged:nil];
        }
        else {
            [SVProgressHUD showInfoWithStatus:@"评论内容不能为空"];
            return NO;
        }
        return NO;
    }
    return YES;
//    NSUInteger proposedNewLength = textView.text.length - range.length + text.length;
//    if ([textView.text isEqualToString:@"回复"]||[textView.text isEqualToString:@"评论"]) {
//        textView.text = @"";
//    }
//    if(text.length==0){
//        return YES;
//    }
//    if (proposedNewLength > 300)
//        return NO;//限制长度
//    return YES;
}
#pragma mark -表情按钮点击
- (IBAction)bqAction:(UIButton *)sender {
    /*
    _inputView.hidden = NO; //这是有输入框的UIView
    XHWEmojiView.hidden = NO; //这是表情KYExpressionInputView
    [XHWEmojiView removeFromSuperview];
    XHWEmojiView = [[KYExpressionInputView alloc] init];
    XHWEmojiView.frame = CGRectMake(0, SCRE_HEIGHT-XHWEmojiView.frame.size.height+5, SCRE_WIDTH, XHWEmojiView.frame.size.height);
    XHWEmojiView.toolbarColor = [UIColor whiteColor];
    XHWEmojiView.backgroundColor = [UIColor whiteColor];
    
//    XHWEmojiView.toolbar.hidden = YES;
    XHWEmojiView.toolbar.hidden = NO;
//    [XHWEmojiView setToolbarSendButtonHidden:YES animated:NO];
    [XHWEmojiView setToolbarSendButtonHidden:NO animated:NO];
    [XHWEmojiView addToolbarItemWithImage:nil title:nil items:[AppDelegate shareDelegate].emojiItems row:KYUIntegerOrientationMake(4, 5) column:KYUIntegerOrientationMake(8, 14) itemSize:KYSizeOrientationMake(CGSizeMake(36, 36), CGSizeMake(36, 36)) itemSpacing:KYFloatOrientationMake(6, 8)];
    XHWEmojiView.delegate = self;
    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:XHWEmojiView];
    [self up:YES];
    NSLog(@"bqAction调用了up方法");
    [self.view endEditing:YES];
    [_hfText resignFirstResponder];
    isUp = YES;
     */
    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:self.emojiView];
    [self up:YES];
    self.isShowEmojiView = YES;
    [self.view endEditing:YES];
    [_hfText resignFirstResponder];
    isUp = YES;
}
/*
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    if ([scrollView isKindOfClass:[UITextView class]]) {
        return;
    }
//    _inputView.hidden = YES;
//    [self.view endEditing:YES];
//    [XHWEmojiView removeFromSuperview];
//    [self up:NO];
//    NSLog(@"scrollViewDidScroll调用了up方法");
    if (self.emojiView) {
        if (isUp) {
            
        }
        else {
            [self up:NO];
        }
//        [self up:NO];
        NSLog(@"scrollViewDidScroll调用了up方法");
        [self.emojiView removeFromSuperview];
    }
    [self.view endEditing:YES];
    [_hfText resignFirstResponder];
    self.isShowEmojiView = NO;
    
}
*/

- (void)inputView:(KYExpressionInputView *)inputViews didSelectExpression:(id<KYExpressionData>)expression {
    NSString *picName = [expression imageUrl];
    NSLog(@"%@",picName);
    NSLog(@"%@",[expression text]);
    NSLog(@"%@",[expression code]);
    NSLog(@"%@",[expression image]);
    NSLog(@"%@",[expression storeKey]);
    [zanview removeFromSuperview];
    if (inputViews.tag == 2016) {
        bq = picName;
        
        DTModel *msg = _model;
        NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
        if ([msg.iszan intValue]==0) {
            [dic setObject:@"1" forKey:@"type"];
        }else{
            [dic setObject:@"0" forKey:@"type"];
        }
        [dic setObject:msg.id forKey:@"id"];
        [dic setObject:picName forKey:@"content"];
        [[BusinessService shareInstance]praise:dic success:^(id result) {
            if ([msg.iszan intValue]==0) {
                [SVProgressHUD showSuccessWithStatus:@"点赞成功"];
            }else{
                [SVProgressHUD showSuccessWithStatus:@"取消成功"];
            }
            [_table Refresh];
        } failure:^(id result) {
            [SVProgressHUD showErrorWithStatus:result];
        }];

        return;
    }
    //Create emoji attachment
    EmojiTextAttachment *emojiTextAttachment = [EmojiTextAttachment new];
    emojiTextAttachment.emojiTag =[NSString stringWithFormat:@"[%@]",picName];
    //Set tag and image
    emojiTextAttachment.image = [UIImage imageNamed:picName];
    emojiTextAttachment.emojiSize = 20;
    emojiTextAttachment.bql = -5;
    //Insert emoji image
    [_hfText.textStorage insertAttributedString:[NSAttributedString attributedStringWithAttachment:emojiTextAttachment]
                                        atIndex:_hfText.selectedRange.location];
    
    //Move selection location
    _hfText.selectedRange = NSMakeRange(_hfText.selectedRange.location + 1, _hfText.selectedRange.length);
}
//-(BOOL)textViewShouldBeginEditing:(UITextView *)textView{
//    [self registerForKeyboardNotifications];
//    return YES;
//}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}
//视图上移的方法
- (void)  up: (BOOL) up
{
    if (isUp) {
        NSLog(@"xhw->up方法开头->isUP->Yes");
    }
    else {
        NSLog(@"xhw->up方法开头->isUP->NO");
    }
    //  键盘退出的frame
//    CGRect frame = XHWEmojiView.frame; //xhw2018-1-31注释
    CGRect frame = self.emojiView.frame;
    //键盘实时y
    CGFloat keyY = frame.origin.y;
    NSLog(@"xhw->DetailsVC->up方法->keyY1->%f",keyY);
//    if (!up) {
//        keyY = SCRE_HEIGHT;
//        isUp = NO; //xhw2018-1-30加
//    }
//    else { //xhw2018-1-30加
//        isUp = YES; //xhw2018-1-30加else 并添加设置isUp的值的代码
//    }
    //xhw2018-1-31加
    if (!up) {
        keyY = SCRE_HEIGHT;
    }
    NSLog(@"xhw->DetailsVC->up方法->keyY2->%f",keyY);
    //屏幕的高度
    CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
    //动画时间
    CGFloat keyDuration = 0.25;
    //执行动画
//    [_inputView removeFromSuperview]; //xhw2018-1-31注释
//    [[[[UIApplication sharedApplication] windows] firstObject] addSubview:_inputView];  //xhw2018-1-31注释
    NSLog(@"xhw_up方法_inputView.frame.y动画前-%f",_inputView.frame.origin.y);
    [UIView animateWithDuration:keyDuration animations:^{
        _inputView.transform = CGAffineTransformMakeTranslation(0, keyY - screenH);
        NSLog(@"xhw_up方法_inputView.frame.y动画后-%f",_inputView.frame.origin.y);
    }];
    if (isUp) {
       NSLog(@"xhw->up方法末尾->isUP->Yes");
    }
    else {
        NSLog(@"xhw->up方法末尾->isUP->NO");
    }
    
}

-(void)viewWillDisappear:(BOOL)animated
{
    _inputView.hidden = YES;
    [self.view endEditing:YES];
    [XHWEmojiView removeFromSuperview];
    [self up:NO];
    NSLog(@"viewWillDisappear调用了up方法");
    _table.refresh = NO;
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [IQKeyboardManager sharedManager].enableAutoToolbar = YES;
    [IQKeyboardManager sharedManager].enable = YES;

}
#pragma mark -添加键盘frame将要改变的通知
- (void)registerForKeyboardNotifications
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWasShownHes:) name:UIKeyboardWillChangeFrameNotification object:nil];
}
#pragma mark -键盘改变了frame
- (void)keyboardWasShownHes:(NSNotification*)noti{
    //改变window的背景颜色
    self.view.window.backgroundColor = _table.backgroundColor;
    //  键盘退出的frame
    CGRect frame = [noti.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
    
    //键盘实时y
    CGFloat keyY = frame.origin.y;
    NSLog(@"xhw->keyboardWasShownHes->keyY->%f",keyY);
    
//    if (XHWEmojiView) {
//        keyY = SCRE_HEIGHT ;
//        isUp = NO;
//        [[NSNotificationCenter defaultCenter] removeObserver:self];
//    }
//
//    if(isUp){
//        keyY = SCRE_HEIGHT ;
//        isUp = NO;
//        [[NSNotificationCenter defaultCenter] removeObserver:self];
//    }
    
    //xhw2018-1-31加
    if (self.isShowEmojiView && isUp == YES) {
        NSLog(@"进到self.emojiView了");
        keyY = SCRE_HEIGHT;
        isUp = NO;
    }
    else {
        if (isUp) {
            keyY = SCRE_HEIGHT;
            isUp = NO;
        }else {
            
        }
    }
    //屏幕的高度
    CGFloat screenH = [[UIScreen mainScreen] bounds].size.height;
    
    //动画时间
    CGFloat keyDuration = [noti.userInfo[UIKeyboardAnimationDurationUserInfoKey] floatValue];
    //执行动画
    NSLog(@"xhw->keyboardWasShowHes->_inputView.frame.origin.y动画前->%f",_inputView.frame.origin.y);
    [UIView animateWithDuration:keyDuration animations:^{
        _inputView.transform = CGAffineTransformMakeTranslation(0, keyY - screenH);
        NSLog(@"xhw->keyboardWasShowHes->_inputView.frame.origin.y动画后->%f",_inputView.frame.origin.y);

    }];
    
}

#pragma mark 个人信息
- (IBAction)toIndividualAction:(UIButton *)sender {
////    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
////    [dic setObject:_model.uid forKey:@"fuid"];
////    //    [SVProgressHUD showWithStatus:@"加载中..."];
////    //    [[BusinessService shareInstance]userDetail:dic success:^(id result) {
////    //        [SVProgressHUD dismiss];
////    //    } failure:^(id result) {
////    //    }];
//    [[NSNotificationCenter defaultCenter ]postNotificationName:@"FriendDetailsMainVC" object:dic];
    UIStoryboard *customerStoryboard = [UIStoryboard storyboardWithName:@"MS"
                                                                 bundle:[NSBundle mainBundle]];
    FriendDetailsMainVC *searchResultDetailController = [customerStoryboard instantiateViewControllerWithIdentifier:@"FriendDetailsMainVC"];
    searchResultDetailController.model = _model;
    [self.navigationController pushViewController:searchResultDetailController animated:YES];
    
    
}
#pragma mark 分享
- (IBAction)shareAction:(UIButton *)sender {
    
    [zanview removeFromSuperview];
    
}

#pragma mark   赞
- (IBAction)praiseAction:(UIButton *)sender {
    
    DTModel *msg = _model;
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    if ([msg.iszan intValue]==0) {
        [dic setObject:@"1" forKey:@"type"];
    }else{
        [dic setObject:@"0" forKey:@"type"];
    }
    [dic setObject:msg.id forKey:@"id"];
    [dic setObject:@"emoji_52" forKey:@"content"];
    [[BusinessService shareInstance]praise:dic success:^(id result) {
        if ([msg.iszan intValue]==0) {
            msg.zancount = [NSString stringWithFormat:@"%d",[msg.zancount intValue]+1];
        }else{
            msg.zancount = [NSString stringWithFormat:@"%d",[msg.zancount intValue]-1];
        }
        if ([msg.iszan intValue]==0) {
            msg.iszan = @"1";
        }else{
            msg.iszan = @"0";
        }
        _model = msg;
        data = [[NSMutableArray alloc] initWithObjects:_model, nil];
        [_table reloadData];
    } failure:^(id result) {
        [SVProgressHUD showErrorWithStatus:result];
    }];
    
   }

- (IBAction)backAction:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

@end
